public class LeetCode11 {

    public static void main(String[] args) {
        System.out.println(maxArea(new int[]{2,3,10,5,7,8,9}));
    }

    public static int maxArea(int[] height) {
        int sum = 0;

        int left = 0;
        int right = height.length - 1;
        sum = 0;//Math.min(height[left], height[right]) * (right - left);
        while (left < right){
            int leftSum = Math.min(height[left], height[right]) * (right - left);
            if(leftSum >= sum){
                sum = leftSum;
            }

            if(height[left] > height[right]){
                right--;
            }else{

                left++;
            }
        }

        return sum;
    }
}
